home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / bathints.zip / BH_04.DOC < prev    next >
Text File  |  1987-10-26  |  8KB  |  183 lines

  1.  
  2.                                   BAT-HINT # 4
  3.  
  4. **************************************************************************
  5.  
  6. from the BATHINTS library... part of the BATPOWER CONFERENCE from:
  7.  
  8.                          THE PAINFRAME OPUS/FIDO 261/1004
  9.  
  10.                         Baltimore, Maryland 1-301-488-7461
  11.  
  12. **************************************************************************
  13.  
  14.                        The ENVIRONMENT and its VARIABLES
  15.  
  16. No, this is not about the weather... but it is a stormy subject for many
  17. users. DOS has a user variable area of memory called the ENVIRONMENT that
  18. is used to store certain types of variables... environmental variables...
  19. whose values are made available to programs. These variables include the
  20. directory path (path variable), the command processor specification
  21. (comspec variable) and the system prompt (prompt variable). Typing the
  22. SET command alone will reveal the values of your current environmental
  23. variables and will always include the COMSPEC= variable. If your prompt is
  24. the DOS default prompt, that variable will not be displayed. The value of
  25. the prompt environmental variable is only displayed by the SET command if
  26. you have set the prompt to a new value.
  27.  
  28. The default capacity of the ENVIRONMENT is 160 bytes for DOS 3.X. This
  29. capacity can be expanded throught the use of the SHELL command in the
  30. config.sys file (see BATHINT file bh_1.doc). The capacity of the
  31. ENVIRONMENT defines the maximum number of bytes that can be present in the
  32. ENVIRONMENT, but DOS expands the ENVIRONMENT as necessary for holding the
  33. values of additional ENVIRONMENTAL VARIABLES. However, this is true only
  34. when there are no memory resident programs loaded in memory. Once a memory
  35. resident program is loaded, DOS cannot expand the capacity of the
  36. ENVIRONMENT beyond 128 bytes, since memory resident programs are loaded
  37. above the memory area earmarked for the ENVIRONMENT. Therefore, using an
  38. expanded ENVIRONMENT is essential if you are running memory resident
  39. programs and also want to SET a long directory path or SET the value of
  40. other custom ENVIRONMENTAL VARIABLES.
  41.  
  42. With an expanded ENVIRONMENT, many variables can be given values using the
  43. SET command and the value of those variables can be called up for use when
  44. needed. Why use ENVIRONMENTAL VARIABLES? Perhaps the best use of the
  45. ENVIRONMENTAL VARIABLE is ridding your system once and for all of that
  46. painful message... Insert disk with command.com. For hard disk users, this
  47. is not much of a problem since command.com resides on a fixed disk. But for
  48. floppy users... Shown below are command lines: one to be placed in the
  49. config.sys file and the other to be placed in your autoexec.bat file:
  50.  
  51.     CONFIG.SYS                         AUTOEXEC.BAT
  52.  
  53.     shell=command.com /e:62 /p         copy command.com d:\
  54.                                        set comspec=d:\command.com
  55.  
  56. The config.sys expands your ENVIRONMENT to the maximum 962 bytes allowable
  57. under DOS 3.1 and the command lines in the autoexec.bat copy the command
  58. processor to your RAM disk d: (you have one don't you?) then sets the value
  59. of COMSPEC (the commmand processor ENVIRONMENTAL VARIABLE) to the the
  60. command.com that was copied into the RAM disk. Now whenever a program needs
  61. to access command.com it will always be found... in the RAM disk (until you
  62. turn off your cpu). Place these commands near the top of your config.sys
  63. and autoexec.bat files.
  64.  
  65. The third line in your autoexec.bat file should SET the value of the PATH
  66. ENVIRONMENTAL VARIABLE. Either of the two command lines shown below will
  67. SET your PATH to the indicated value:
  68.  
  69.     set path=d:\;c:\bat;c:\dos;c:\util            or
  70.     path=d:\;c:\bat;c:\dos;c:\util
  71.  
  72. Use of the SET command is not necessary for either the PATH or PROMPT
  73. ENVIRONMENTAL VARIABLES.
  74.  
  75. A fantastic little program written by Frank Schweiger is ANSWER.COM. This
  76. program and its documentation have been bundled with several other useful
  77. programs in the BATPOWER CONFERENCE file BATPOWER.ARC. When used in a batch
  78. file, ANSWER pauses execution of the batch file, displays an optional
  79. message string following the ANSWER command and accepts input from the
  80. standard device (i.e. the console...) until a carriage return is sent (ASCI
  81. 13). ANSWER then sets the value of the ANSWER ENVIRONMENTAL VARIABLE to the
  82. input received between pausing and the carriage return. This allows the
  83. user at the console to enter ENVIRONMENTAL VARIABLES that can be used or
  84. tested at a later time. For example, assuming that ANSWER.COM is in the
  85. current directory or can be found in the directory path, the following
  86. sample.bat file waits for input from the console:
  87.  
  88.     SAMPLE.BAT
  89.  
  90.     echo off
  91.     answer What is your name?
  92.  
  93. The user might type the letters... John, then press return. The next few
  94. lines in the batch file might then be:
  95.  
  96.     cls
  97.     echo Your name is %answer%
  98.  
  99. The monitor would then display the following statement:
  100.  
  101.     Your name is John
  102.  
  103. Simple enough, but now you have this guys name in the ENVIRONMENT. Thus,
  104. each and every time you wish to refer to this user you need only call up
  105. the ENVIRONMENTAL VARIABLE assigned the value... John... in this case that
  106. ENVIRONMENTAL VARIABLE is ANSWER. One hitch is that each and every time you
  107. run the program ANSWER.COM as shown above in sample.bat, the ANSWER
  108. ENVIRONMENTAL VARIABLE is reset. You can store the value of answer in
  109. another ENVIRONMENTAL VARIABLE of your choice using the SET command, to
  110. alleviate this problem. For example, the sample2.bat file shown below
  111. accomplishes the same task as sample.bat shown above, but reassigns the
  112. value of ANSWER to a new ENVIRONMENTAL VARIABLE called NAME:
  113.  
  114.     echo off
  115.     answer What is your name?
  116.     set name=%answer%
  117.     cls
  118.     echo Your name is %name%
  119.  
  120. The result will be the same. Now there are two ENVIRONMENTAL VARIABLES with
  121. the same value... both NAME and ANSWER are equal to... John. The value of
  122. an ENVIRONMENTAL VARIABLE can be cleared from memory with the following
  123. command:
  124.  
  125.     set variable=
  126.  
  127. where the word variable is the ENVIRONMENTAL VARIABLE in question... in our
  128. examples... NAME and ANSWER. When the value of an ENVIRONMENTAL VARIABLE is
  129. no longer needed, the command shown above should be used to free up
  130. available memory allocated to the ENVIRONMENT.
  131.  
  132. Notice that in the examples shown above that when the value of the
  133. ENVIRONMENTAL VARIABLE is to be used, the VARIABLENAME (i.e. NAME or
  134. ANSWER) must be enclosed with % symbols. This is how DOS distinguishes
  135. ENVIRONMENTAL VARIABLES from normal text.
  136.  
  137. As a more extensive example, examine the following batch file:
  138.  
  139.     WORDPRO.BAT
  140.  
  141.     echo off
  142.     cls
  143.     c:
  144.     cd\wp
  145.     echo Entering WordPerfect...
  146.     answer What drive contains your document?
  147.     set wpdrive=%answer%
  148.     cls
  149.     answer What subdirectory?
  150.     set wppath=%answer%
  151.     cls
  152.     answer What is the name of your document?
  153.     set document=%answer%
  154.     if exist %wpdrive%:\%wppath%\%document% goto doit
  155.     cls
  156.     echo The directory %wppath% or the document %document% does not exist!
  157.     echo Please try again!
  158.     goto fini
  159.     :doit
  160.     wp %wpdrive%:\%wppath%\%document%
  161.     set wpdrive=
  162.     set wppath=
  163.     set document=
  164.     set answer=
  165.     :fini
  166.     cd\
  167.  
  168. WORDPRO.BAT prompts the user for the name of the drive, subdirectory, and
  169. document to be edited by WordPerfect and sets each of the values of the
  170. WPDRIVE, WPPATH AND DOCUMENT ENVIRONMENTAL VARIABLES to the value set to
  171. ANSWER, respectively. It then checks for the existence of this document and
  172. if it exists it passes these ENVIRONMENTAL VARIABLES as parameters to the
  173. command line containing the wp command. If the document does not exist,
  174. WORDPRO.BAT informs the user and kicks him out to the end of the batch
  175. file. When WordPerfect is exited, WORDPRO.BAT clears the values of the
  176. ENVIRONMENTAL VARIABLES and changes the directory back to the root
  177. directory. Believe it or not, I employ these types of batch files everyday
  178. in systems operated by DOS novices. No complaints. I am sure you can devise
  179. many ways to use s